import requests
from common.ihrm_token import ihrm_login
from config import host


class IhrmUserApi:
    add_url = host + "/api/sys/user"
    user_url = host + "/api/sys/user/"
    head = {"Authorization": ihrm_login()}

    # 添加员工接口
    @classmethod
    def ihrm_user_add(cls, add_json):
        # 执行接口请求
        resp = requests.post(url=cls.add_url, json=add_json, headers=cls.head)
        print(resp.json())
        return resp

    # 修改员工接口
    @classmethod
    def ihrm_user_edit(cls, user_id, edit_json):
        # 执行接口请求
        req_url = cls.user_url + user_id
        resp = requests.put(url=req_url, json=edit_json, headers=cls.head)
        return resp

    # 删除员工接口
    @classmethod
    def ihrm_user_delete(cls, user_id):
        # 执行接口请求
        req_url = cls.user_url + user_id
        resp = requests.delete(url=req_url, headers=cls.head)
        return resp

    # 查询员工
    @classmethod
    def ihrm_user_get(cls, user_id):
        # 执行接口请求
        req_url = cls.user_url + user_id
        resp = requests.get(url=req_url, headers=cls.head)
        return resp

    # 员工列表
    @classmethod
    def ihrm_user_list(cls, page=1, size=10):
        # 执行接口请求
        req_params = {"page": page, "size": size}
        resp = requests.get(url=cls.add_url, params=req_params, headers=cls.head)
        return resp
